import gtk.gdk
import time

w = gtk.gdk.get_default_root_window()
sz = w.get_size()
w_mod = 3
h_mod = 2
print "The size of the window is %d x %d" % sz
i = 0
while(1):
	start_time = time.time()
	pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0]/w_mod,sz[1]/h_mod)
	pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0]/w_mod,sz[1]/h_mod)
	if (pb != None):
    		pb.save("screenshot" + str(i) + ".png","png")
    		print "Screenshot saved to screenshot" + str(i) + ".png."
		i=i+1
	else:
    		print "Unable to get the screenshot."
	end_time = time.time()
	print "Time used: " + str(end_time - start_time)

